﻿using Coldairarrow.Business.Base_Manage;
using Coldairarrow.Entity.DomainModels;
using Coldairarrow.Util;
using Coldairarrow.Util.Utilities;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Coldairarrow.Api.Controllers.Base_Manage
{
    [Route("/Base_Manage/[controller]/[action]")]
    [OpenApiTag("BuildSuper")]
    public class BuildSuperCodeController : BaseApiController
    {
        #region DI

        public BuildSuperCodeController(IBuildSuperCodeBusiness buildSuperCodeBus)
        {
            _buildSuperCodeBus = buildSuperCodeBus;
        }

        IBuildSuperCodeBusiness _buildSuperCodeBus { get; }

        #endregion

       
        /// <summary>
        /// 获取代码生成器模板列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("GetTableTree")]
        public async Task<List<BuilderCodeTreeDTO>> GetBuildListTree()
        {

           return await _buildSuperCodeBus.GetBuildListTree();

        }



        /// <summary>
        /// 界面加载表的配置信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Route("LoadTableInfo")]
        [HttpPost]
        public async Task<object> LoadTable(TabeInfo input)
        {
            return await _buildSuperCodeBus.LoadTable(input);

        }
        /// <summary>
        /// 新建配置信息保存
        /// </summary>
        /// <param name="tableInfo"></param>
        /// <returns></returns>
        [Route("Save")]
        [HttpPost]
        public async Task<WebResponseContent> SaveEidt([FromBody] Sys_TableInfo tableInfo)
        {
          return  await _buildSuperCodeBus.SaveEidt(tableInfo);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="table_Id"></param>
        /// <returns></returns>
        [Route("delTree")]
        [HttpPost]
        public async Task<WebResponseContent> DelTree(int table_Id)
        {
            return await _buildSuperCodeBus.DelTree(table_Id);
        }
        /// <summary>
        /// 同步表结构
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        [Route("syncTable")]
        [HttpPost]
        public async Task<object> SyncTable(string tableName)
        {
            return await _buildSuperCodeBus.SyncTable(tableName);
        }
        /// <summary>
        /// 生成实体类
        /// </summary>
        /// <param name="tableInfo"></param>
        /// <returns></returns>
        [Route("CreateModel")]
        [HttpPost]
        public async Task<WebResponseContent> CreateEntityModel([FromBody] Sys_TableInfo tableInfo)
        {
            return await _buildSuperCodeBus.CreateEntityModel(tableInfo);
        }
       
        /// <summary>
        /// 代码生成(buildTypes:业务层=1,接口层=2)
        /// </summary>
        /// <param name="input"></param>
        [Route("BuildCode")]
        [HttpPost]
        public string BuildSuperCode(BuildSuperInputDTO input)
        {
          return  _buildSuperCodeBus.BuildSuperCode(input);

        }

       
        /// <summary>
        /// 生成Vue页面
        /// </summary>
        /// <param name="sysTableInfo"></param>
        /// <returns></returns>
        [Route("CreateVuePage")]
        //[ApiActionPermission(ActionRolePermission.SuperAdmin)]
        [HttpPost]
        public ActionResult CreateVuePage([FromBody] Sys_TableInfo sysTableInfo)
        {
            return Content(_buildSuperCodeBus.CreateVuePage(sysTableInfo));
        }
    }
}